package com.shop.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class JSONResponse<T> {

    @ApiModelProperty(value = "状态码")
    private String result = "";

    @ApiModelProperty(value = "状态描述")
    private String resultDesc = "";

    @ApiModelProperty(value = "响应数据")
    private T data;

    private final static String RESULT_SUCCESS = "000000";

    private final static String RESULT_DESC_SUCCESS = "请求成功";

    private final static String SYSTEM_ERROR = "100000";


    public static JSONResponse ok(Object data){
        JSONResponse jsonResponse = new JSONResponse<>();
        jsonResponse.setResult(RESULT_SUCCESS);
        jsonResponse.setResultDesc(RESULT_DESC_SUCCESS);
        jsonResponse.setData(data);
        return jsonResponse;
    }

    public static JSONResponse ok(){
        JSONResponse jsonResponse = new JSONResponse<>();
        jsonResponse.setResult(RESULT_SUCCESS);
        jsonResponse.setResultDesc(RESULT_DESC_SUCCESS);
        return jsonResponse;
    }

    public static JSONResponse error(String message){
        JSONResponse jsonResponse = new JSONResponse<>();
        jsonResponse.setResult(SYSTEM_ERROR);
        jsonResponse.setResultDesc(message);
        return jsonResponse;
    }


}
